/* sod.t - SO_MSTR delete trigger                                            */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                       */
/* All rights reserved worldwide.  This is an unpublished work.              */
/* $Revision: 1.1 $                                                         */
/*                                                                           */
/* This program will delete external storefront order xref records from      */
/* qad_wkfl when corresponding so_mstr records are deleted.                  */
/*                                                                           */
/* $Revision: 1.1 $   BY: John Pison            DATE:01/25/01   ECO: *N0VZ* */
/*                                                                           */
/*V8:ConvertMode=NoConvert                                                   */


TRIGGER PROCEDURE FOR DELETE OF so_mstr.

/*fdn*/    {mfdeclre.i }
/*fdn*/    define new shared work-table wf_old_so_mstr like so_mstr.


/* Identifier for procedure that adds these workfile records */
&SCOPED-DEFINE WORKFILE-KEY ncapis.p

/* Delete storefront order xref record for the current SO */
for first qad_wkfl exclusive-lock where
   qad_key1 = "{&WORKFILE-KEY}" and
   qad_key2 = so_nbr:

   delete qad_wkfl.

end.  /* for */

	HK:
	do:
        if not can-find ( first dt_mstr where dt_table = "so_mstr" and dt_type = "DEL" ) then leave HK.
        
        if not can-find ( first wf_old_so_mstr ) then do:
            create wf_old_so_mstr.
            if recid(wf_old_so_mstr)= -1 then .
        end.
        
        buffer-copy so_mstr to wf_old_so_mstr no-error.

        for first dt_mstr no-lock where dt_table = "so_mstr" and dt_type = "DEL" :
        
			run value(global_user_lang_dir + "hk/hktrigdel.p")
       			"wf_old_so_mstr"		/*old buffer*/
       			""						/*new buffer*/
       			dt_table				/*table name*/
       			""						/*field name*/
       			dt_type					/*type*/
       			recid(so_mstr)			/*key*/	
       			so_mstr.so_nbr			/*key1*/
       			""						/*key2*/
       			""						/*key3*/
       			""						/*key4*/
       			""						/*key5*/
       			""						/*key6*/
       			""						/*key7*/
       			""						/*key8*/
       			.
			
        end.
	end.
